package com.hl;

import com.hl.entity.Teacher;
import com.hl.mapper.TeacherMapper;
import com.hl.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

/**
 * 动态SQL测试
 * */
public class Test4Dynamic {
    public static void main(String[] args) throws IOException {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);

        Teacher teacher = new Teacher();
        teacher.setTname("张三");
        teacher.setTid(1);
        // teacher.setCollegeId(1);
        List<Teacher> list1 = mapper.selectTeacherDynamic1(teacher);
        for (Teacher teacher1 : list1) {
            System.out.println(teacher1);
        }

        Teacher teacher2 = new Teacher();
        teacher2.setTname("张三");
        teacher2.setTid(2);
        teacher2.setCollegeId(3);
        List<Teacher> list2 = mapper.selectTeacherDynamic2(teacher2);
        for (Teacher teacher1 : list2) {
            System.out.println(teacher1);
        }

        Teacher teacher3 = new Teacher();
        teacher3.setTname("张三丰");
        teacher3.setTid(1);
        // teacher3.setCollegeId(1);
        int row = mapper.updateTeacherDynamic(teacher3);
        System.out.println(row >0? "修改成功":"修改失败");

        MybatisUtils.closeSqlSession(sqlSession);

    }

}
